using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class FlirtIconDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public FlirtIconDA()
		{
		}

		public FlirtIconDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the FlirtIcons table.
		/// </summary>
		public  int Insert(FlirtIcon flirtIcon)
		{
			ValidationUtility.ValidateArgument("flirtIcon", flirtIcon);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", flirtIcon.TenantID),
				new SqlParameter("@ImageName", flirtIcon.ImageName),
				new SqlParameter("@ImageMessage", flirtIcon.ImageMessage)
			};

			flirtIcon.IconID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "FlirtIconsInsert", parameters));
			return flirtIcon.IconID;
		}

		/// <summary>
		/// Updates a record in the FlirtIcons table.
		/// </summary>
		public  int Update(FlirtIcon flirtIcon)
		{
			ValidationUtility.ValidateArgument("flirtIcon", flirtIcon);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IconID", flirtIcon.IconID),
				new SqlParameter("@TenantID", flirtIcon.TenantID),
				new SqlParameter("@ImageName", flirtIcon.ImageName),
				new SqlParameter("@ImageMessage", flirtIcon.ImageMessage)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "FlirtIconsUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the FlirtIcons table by its primary key.
		/// </summary>
		public  int Delete(int iconID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IconID", iconID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "FlirtIconsDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the FlirtIcons table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "FlirtIconsDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the FlirtIcons table.
		/// </summary>
		public  FlirtIcon Select(int iconID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IconID", iconID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "FlirtIconsSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeFlirtIcon(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the FlirtIcons table.
		/// </summary>
		public  List<FlirtIcon> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "FlirtIconsSelectAll", parameters))
			{
				List<FlirtIcon> flirtIconList = new List<FlirtIcon>();
				while (dataReader.Read())
				{
					FlirtIcon flirtIcon = MakeFlirtIcon(dataReader);
					flirtIconList.Add(flirtIcon);
				}

				return flirtIconList;
			}
		}

		/// <summary>
		/// Selects all records from the FlirtIcons table by a foreign key.
		/// </summary>
		public  List<FlirtIcon> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "FlirtIconsSelectAllByTenantID", parameters))
			{
				List<FlirtIcon> flirtIconList = new List<FlirtIcon>();
				while (dataReader.Read())
				{
					FlirtIcon flirtIcon = MakeFlirtIcon(dataReader);
					flirtIconList.Add(flirtIcon);
				}

				return flirtIconList;
			}
		}

		/// <summary>
		/// Creates a new instance of the FlirtIcons class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  FlirtIcon MakeFlirtIcon(SqlDataReader dataReader)
		{
			FlirtIcon flirtIcon = new FlirtIcon();
			flirtIcon.IconID = SqlClientUtility.GetInt32(dataReader, "IconID", 0);
			flirtIcon.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			flirtIcon.ImageName = SqlClientUtility.GetString(dataReader, "ImageName", String.Empty);
			flirtIcon.ImageMessage = SqlClientUtility.GetString(dataReader, "ImageMessage", String.Empty);

			return flirtIcon;
		}

		#endregion
	}
}
